#include "StdAfx.h"
#include "ConfigException.h"


ConfigException::ConfigException(uint32 errorCode, const std::string& function)
{
	#ifdef WIN32
		LPSTR message = NULL;
		if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, errorCode, LANG_SYSTEM_DEFAULT, (LPSTR)&message, 0, NULL) > 0)
		{
			LPSTR nl = strchr(message, '\r');
			if(nl != NULL)
				*nl = '\0';

			std::stringstream strm;
			if(function == "")
				strm << "An exception using a Config function occured:" << std::endl << message;
			else
				strm << "An exception using the Config function '" << function << "' occured:" << std::endl << message;

			mMessage = strm.str();
		}
		else
		{
			std::stringstream strm;
			if(function == "")
				strm << "An exception using a Config function occured. The error code is not recognized: 0x" << std::hex << errorCode;
			else
				strm << "An exception using the Config function '" << function << "' occured. The error code is not recognized: 0x" << std::hex << errorCode;
			mMessage = strm.str();
		}
	#else
	#endif
}
